﻿// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.Text.Json.Serialization;

namespace Microsoft.Azure.WebPubSub.Common;

#nullable enable

/// <summary>
/// MQTT Request context from headers following CloudEvents.
/// </summary>
[DataContract]
public class MqttConnectionContext : WebPubSubConnectionContext
{
    internal const string PhysicalConnectionIdProperty = "physicalConnectionId";
    internal const string SessionIdProperty = "sessionId";

    /// <summary>
    /// The unique identifier generated by the service of the network connection.
    /// </summary>
    [JsonPropertyName(PhysicalConnectionIdProperty)]
    [DataMember(Name = PhysicalConnectionIdProperty)]
    public string PhysicalConnectionId { get; }

    /// <summary>
    /// The unique identifier generated by the service of the MQTT session.
    /// </summary>
    [JsonPropertyName(SessionIdProperty)]
    [DataMember(Name = SessionIdProperty)]
    public string? SessionId { get; }

    /// <summary>
    /// The MQTT  connection context contains the CloudEvents headers under Web PubSub protocol.
    /// </summary>
    /// <param name="eventType"></param>
    /// <param name="eventName"></param>
    /// <param name="hub"></param>
    /// <param name="connectionId"></param>
    /// <param name="physicalConnectionId"></param>
    /// <param name="sessionId"></param>
    /// <param name="userId"></param>
    /// <param name="signature"></param>
    /// <param name="origin"></param>
    /// <param name="connectionStates"></param>
    /// <param name="headers"></param>
    public MqttConnectionContext(WebPubSubEventType eventType, string eventName, string hub, string connectionId, string physicalConnectionId, string? sessionId, string? userId = null, string? signature = null, string? origin = null, IReadOnlyDictionary<string, BinaryData>? connectionStates = null, IReadOnlyDictionary<string, string[]>? headers = null) : base(eventType, eventName, hub, connectionId, userId, signature, origin, connectionStates, headers)
    {
        PhysicalConnectionId = physicalConnectionId;
        SessionId = sessionId;
    }
}
